/**
 * 2
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-10-23 上午9:57
 */

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> value(n);
    vector<int> cost(n);
    for (int i = 0; i < n; ++i) {
        cin >> value[i] >> cost[i];
    }

    vector<vector<int>> f(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            f[i][j] = f[i - 1][j];
            if (j >= cost[i - 1]) {
                f[i][j] = max(f[i][j], f[i - 1][j - cost[i - 1]] + cost[i - 1] - value[i - 1]);
            }
        }
    }

    cout << f[n][m] << endl;

    return 0;
}